package com.shchuangzhi.smartguard.core;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by j_hu on 5/11/17.
 */

public class NotifyMessage {
    private Object data;
    private String time;
    private String level;
    private String message;
    private List<Integer> targets;

    public static final String LEVEL_INFO = "事件";
    public static final String LEVEL_ERROR = "异常";
    public static final String LEVEL_DATA = "Wrap";

    private NotifyMessage(String level, String message, int... targets) {
        this(level, message, targets, targets);
    }

    private NotifyMessage(String level, String message, Object data, int... targets) {
        this.level = level;
        this.message = message;
        this.data = data;
        this.targets = new ArrayList<>();
        this.time = new SimpleDateFormat("HH:mm:ss").format(new Date());
        if (targets != null) {
            for(int t : targets) {
                this.targets.add(t);
            }
        }
    }

    public String getLevel() {
        return level;
    }

    public String getMessage() {
        return message;
    }

    public String getTime() {
        return time;
    }

    public List<Integer> getTargets() { return targets; }

    public Object getData() { return data; }

    public static NotifyMessage info(String message, int... targets) {
        return new NotifyMessage(LEVEL_INFO, message, targets);
    }

    public static NotifyMessage error(String message, int... targets) {
        return new NotifyMessage(LEVEL_ERROR, message, targets);
    }

    public static NotifyMessage wrap(Object data, int... targets) {
        return new NotifyMessage(LEVEL_DATA, "", data, targets);
    }
}
